package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Notice;
import cn.wolfcode.mapper.NoticeMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.INoticeService;
import cn.wolfcode.util.UserContextUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper,Notice> implements INoticeService {

    @Override
    public Page<Notice> queryPage(QueryObject qo) {
        Page<Notice> page = new Page<>(qo.getCurrentPage(),qo.getPageSize());
        QueryWrapper<Notice> wrapper = new QueryWrapper<>();
        return super.page(page,wrapper);
    }

    @Override
    public List<Long> markReadAll(Long id) {
        List<Long> list = this.baseMapper.markReadAll(id);
        return  list;
    }

    @Override
    public void insertReadStatus(Long id, Long nid) {
        this.baseMapper.insertReadStatus(id,nid);
    }

    @Override
    public boolean save(Notice entity) {
        entity.setCreationTime(new Date());
        entity.setCreationId(UserContextUtil.getUserContext().getId());
        return super.save(entity);
    }
}
